import cPickle
import zlib

def Object2String(dataObj, CompressMode = True):
    retString = cPickle.dumps( dataObj , 2)
    if CompressMode: retString = zlib.compress(retString)
    return retString

def String2Object(dataString, CompressMode = True):
    if CompressMode: dataString = zlib.decompress( dataString )
    retObj = cPickle.loads( dataString )
    return retObj